/*
 * @lc app=leetcode.cn id=1507 lang=javascript
 *
 * [1507] 转变日期格式
 */

// @lc code=start
/**
 * @param {string} date
 * @return {string}
 */
var reformatDate = function (date) {
  const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  let [day, month, year] = date.split(' ');
  day = day.match(/[0-9]+/)[0];
  day = day.length === 1 ? `0${day}` : day;
  month = `${months.indexOf(month) + 1}`;
  month = month.length === 1 ? `0${month}` : month;
  return `${year}-${month}-${day}`
};
// @lc code=end
const res = reformatDate("6th Jun 1933");
console.log(res);
